package com.dqhl.community.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dqhl.community.R;
import com.dqhl.community.activity.ExpressReceiveActivity;
import com.dqhl.community.activity.HospitalActivity;
import com.dqhl.community.activity.ShoppingOnlineActivity;
import com.dqhl.community.base.BaseFragment;

/**
 * Created by cheng on 2016/8/29.
 * 生活 fragment
 */
public class LifeFragment extends BaseFragment implements View.OnClickListener {


    private TextView tvTopTitle;

    private ImageView iv_information;//消息
    private ImageView iv_medical_two; //社区医疗


    private LinearLayout ll_food;//在线超市Activity
    private LinearLayout ll_hosipital;//社区医疗
    private LinearLayout ll_taxi;//滴滴打车Activity
    private LinearLayout ll_wash;//干洗衣物Activity
    private LinearLayout ll_inquire_one;//快递查询Activity
    private ImageView iv_inquire_two; //快递查询（下面的）
    private LinearLayout ll_group;//特惠团购Activity
    private LinearLayout ll_weekend;//周末游玩Activity
    private LinearLayout ll_safe;//保险基金Activity


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_life, container, false);
        initView(view);
        return view;
    }

    // 实例化对象
    private void initView(View view) {
        tvTopTitle = (TextView) view.findViewById(R.id.tv_top_title);
        tvTopTitle.setText("生活服务");
        iv_information = (ImageView) view.findViewById(R.id.iv_top_operation);
        iv_information.setVisibility(View.VISIBLE);
        ll_food = (LinearLayout) view.findViewById(R.id.ll_foods);
        ll_hosipital = (LinearLayout) view.findViewById(R.id.ll_hosipital);
        iv_medical_two = (ImageView) view.findViewById(R.id.iv_medical_two);
        ll_taxi = (LinearLayout) view.findViewById(R.id.ll_taxi);
        ll_wash= (LinearLayout) view.findViewById(R.id.ll_wash);
        ll_inquire_one = (LinearLayout) view.findViewById(R.id.ll_inquire);
        iv_inquire_two = (ImageView) view.findViewById(R.id.iv_inquire_two);
        ll_group = (LinearLayout) view.findViewById(R.id.ll_group);
        ll_weekend = (LinearLayout) view.findViewById(R.id.ll_weekend);
        ll_safe = (LinearLayout) view.findViewById(R.id.ll_safe);
        iv_inquire_two = (ImageView) view.findViewById(R.id.iv_inquire_two);

        iv_information.setOnClickListener(this);
        ll_food.setOnClickListener(this);
        ll_hosipital.setOnClickListener(this);
        iv_medical_two.setOnClickListener(this);
        ll_taxi.setOnClickListener(this);
        ll_wash.setOnClickListener(this);
        ll_inquire_one.setOnClickListener(this);
        ll_group.setOnClickListener(this);
        ll_weekend.setOnClickListener(this);
        ll_safe.setOnClickListener(this);
        iv_inquire_two.setOnClickListener(this);
    }

    //控件的点击事件
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            // 消息
            case R.id.iv_top_operation:
                toast("暂无消息");
                break;
            //在线超市
            case R.id.ll_foods:
                if ("".equals(app.getUserId()) || app.getUserId() == null) {
                    toast("请先登录");
                } else {
                    overlay(ShoppingOnlineActivity.class);
                }
                break;
            //社区医疗
            case R.id.ll_hosipital:
            case R.id.iv_medical_two:
                if ("".equals(app.getUserId()) || app.getUserId() == null) {
                    toast("请先登录");
                } else {
                    overlay(HospitalActivity.class);
                }
                break;
            //滴滴打车
            case R.id.ll_taxi:
                if ("".equals(app.getUserId()) || app.getUserId() == null) {
                    toast("请先登录");
                } else {
//                    overlay(HospitalActivity.class);
                    toast("页面没有");
                }
                break;
            //干洗衣物
            case R.id.ll_wash:
                if ("".equals(app.getUserId()) || app.getUserId() == null) {
                    toast("请先登录");
                } else {
//                    overlay(HospitalActivity.class);
                    toast("页面没有");
                }
                break;
            //快递查询
            case R.id.ll_inquire:
            case R.id.iv_inquire_two: //快递查询（下）
                if ("".equals(app.getUserId()) || app.getUserId() == null) {
                    toast("请先登录");
                } else if ("".equals(app.getAuthentication()) || app.getAuthentication() == null) {
                    toast(R.string.toast_go_to_auth);
                } else {
                    overlay(ExpressReceiveActivity.class);
                }
                break;
            //特惠团购
            case R.id.ll_group:
                if ("".equals(app.getUserId()) || app.getUserId() == null) {
                    toast("请先登录");
                } else {
//                    overlay(HospitalActivity.class);
                }
                toast("页面没有");
                break;
            // 周末游玩
            case R.id.ll_weekend:
                if ("".equals(app.getUserId()) || app.getUserId() == null) {
                    toast("请先登录");
                } else {
//                    overlay(HospitalActivity.class);
                }
                toast("周末游玩");
                break;
            //保险基金
            case R.id.ll_safe:
                if ("".equals(app.getUserId()) || app.getUserId() == null) {
                    toast("请先登录");
                } else {
//                    overlay(HospitalActivity.class);
                    toast("保险基金");
                }
                break;

        }
    }
}
